package com.thread;

/*
主线程每隔1s，输出hi,一共10次
当输出到hi5时，启动一个子线程(要求实现Runnable)，每隔1s输出hello,等该线程输出10次 hello后，退出
主线程继续输出hi，直到主线程退出.
 */
public class ThreadMethodExercise {
    public static void main(String[] args) throws InterruptedException{
        Thread thread1 = new Thread(new T5());
        for (int i = 0 ; i < 10 ;++i){
            System.out.println("hi"+ i);
            if (i ==5 ){
                thread1.start();
                thread1.join();
            }
            Thread.sleep(1000);
        }


    }
}

class T5 implements Runnable{
    private  int count = 0;
    @Override
    public void run() {

        while (true){
            System.out.println("hello"+ ++count);
            try {
                Thread.sleep(1000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
            if (count==10){
                return;
            }
        }
    }
}
